// 基础交互逻辑
document.querySelectorAll('.nav-item').forEach(item => {
    item.addEventListener('click', function() {
        document.querySelector('.nav-item.active').classList.remove('active');
        this.classList.add('active');
        toggleSections(this.textContent.trim());
    });
});
// 新增需求广场交互逻辑
document.addEventListener('click', function(e) {
    // 预览按钮点击
    if (e.target.classList.contains('preview-btn')) {
        document.querySelector('.demand-grid').style.display = 'none';
        document.querySelector('.demand-detail').style.display = 'block';
        document.querySelector('.middle-area').style.display = 'none';
    }
    
    // 返回按钮点击
    if (e.target.classList.contains('return-btn')) {
        document.querySelector('.demand-grid').style.display = 'grid';
        document.querySelector('.demand-detail').style.display = 'none';
        document.querySelector('.middle-area').style.display = 'block';
    }
    
});



// 下拉菜单显示隐藏
document.querySelectorAll('.dropdown').forEach(dropdown => {
    dropdown.addEventListener('click', function() {
        const content = this.querySelector('.dropdown-content');
        content.style.display = content.style.display === 'block' ? 'none' : 'block';
    });
});
// 切换显示的部分
function toggleSections(activeTab) {
    const container = document.querySelector('.container');
    const messagesContainer = document.querySelector('.messages-container');
    const changePasswordContainer = document.querySelector('.change-password-container');
    container.style.display = 'none';
    messagesContainer.style.display = 'none';
    changePasswordContainer.style.display = 'none';

    if (activeTab === '消息') {
        messagesContainer.style.display = 'flex';
    }else {
        container.style.display = 'flex';
    }
}

// 初始化显示需求广场
   document.addEventListener('DOMContentLoaded', () => {
       toggleSections('需求广场'); 
   });
// 用户信息下拉菜单
document.querySelector('.user-info').addEventListener('click', function() {
    const dropdown = this.querySelector('.user-dropdown');
    dropdown.style.display = dropdown.style.display === 'block' ? 'none' : 'block';
});

// 修改密码按钮逻辑
document.getElementById('change-password-btn').addEventListener('click', function() {
    document.querySelector('.change-password-container').style.display = 'flex';
    document.querySelector('.user-dropdown').style.display = 'none';
});

// 返回按钮逻辑
document.getElementById('return-to-user-info').addEventListener('click', function() {
    document.querySelector('.change-password-container').style.display = 'none';
    document.querySelector('.user-dropdown').style.display = 'block';
});

// 回复按钮逻辑
document.querySelectorAll('.reply-btn').forEach(button => {
    button.addEventListener('click', function() {
        const replyBox = this.parentElement.parentElement.nextElementSibling;
        replyBox.style.display = replyBox.style.display === 'flex' ? 'none' : 'flex';
    });
});